package com.zucc.controller;

import com.zucc.controller.req.NewsAddReq;
import com.zucc.controller.req.NewsModifyReq;
import com.zucc.controller.req.NewsSearchReq;
import com.zucc.controller.resp.NewsResp;
import com.zucc.service.NewsService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-11 4:43 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/newses")
@Api(tags = "新闻管理")
public class NewsController {
    @Resource
    private NewsService newsService;

    @ApiOperation(value = "新增新闻")
    @PostMapping
    void add(@RequestBody @Validated NewsAddReq req) {
        newsService.add(req);
    }

    @ApiOperation(value = "处理新闻")
    @PutMapping
    void modify(@RequestBody @Validated NewsModifyReq req) {
        newsService.modify(req);
    }

    @ApiOperation(value = "删除新闻")
    @ApiImplicitParam(paramType = "path", name = "id", value = "新闻编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/{id}")
    void deleteOne(@PathVariable Long id) {
        newsService.deleteOne(id);
    }

    @ApiOperation(value = "新闻分页")
    @PostMapping("/page")
    PageData<NewsResp> page(@RequestBody @Validated NewsSearchReq req) {
        return newsService.page(req);
    }
}
